-
Notifications
You must be signed in to change notification settings - Fork 497
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Yusuf Kanchwala
committed
Sep 30, 2020
1 parent
464573e
commit ad87651
Showing
1 changed file
with
133 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
/* | ||
Copyright (C) 2020 Accurics, Inc. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package downloader | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func TestNewGoGetter(t *testing.T) { | ||
t.Run("new GoGetter", func(t *testing.T) { | ||
var ( | ||
want = &GoGetter{} | ||
got = NewGoGetter() | ||
) | ||
if !reflect.DeepEqual(got, want) { | ||
t.Errorf("got: '%v', want: '%v'", got, want) | ||
} | ||
}) | ||
} | ||
|
||
func TestGetURLSubDir(t *testing.T) { | ||
|
||
table := []struct { | ||
name string | ||
URL string | ||
dest string | ||
wantURL string | ||
wantSubDir string | ||
wantErr error | ||
}{ | ||
{ | ||
name: "github url no subdir", | ||
URL: "github.com/accurics/terrascan", | ||
dest: "some-dest", | ||
wantURL: "git::https://github.com/accurics/terrascan.git", | ||
wantSubDir: "", | ||
wantErr: nil, | ||
}, | ||
{ | ||
name: "github url with subdir", | ||
URL: "github.com/accurics/terrascan//some-subdir", | ||
dest: "some-dest", | ||
wantURL: "git::https://github.com/accurics/terrascan.git", | ||
wantSubDir: "some-subdir", | ||
wantErr: nil, | ||
}, | ||
{ | ||
name: "github ssh url", | ||
URL: "[email protected]:accurics/terrascan.git//some-subdir", | ||
dest: "some-dest", | ||
wantURL: "git::ssh://[email protected]/accurics/terrascan.git", | ||
wantSubDir: "some-subdir", | ||
wantErr: nil, | ||
}, | ||
{ | ||
name: "github basic auth", | ||
URL: "git::ssh://[email protected]/storage.git//some-subdir", | ||
dest: "some-dest", | ||
wantURL: "git::ssh://[email protected]/storage.git", | ||
wantSubDir: "some-subdir", | ||
wantErr: nil, | ||
}, | ||
{ | ||
name: "github ref version", | ||
URL: "git::https://example.com/vpc.git?ref=v1.2.0", | ||
dest: "some-dest", | ||
wantURL: "git::https://example.com/vpc.git?ref=v1.2.0", | ||
wantSubDir: "", | ||
wantErr: nil, | ||
}, | ||
{ | ||
name: "http url", | ||
URL: "https://example.com/vpc-module.zip", | ||
dest: "some-dest", | ||
wantURL: "https://example.com/vpc-module.zip", | ||
wantSubDir: "", | ||
wantErr: nil, | ||
}, | ||
{ | ||
name: "http url with basic auth", | ||
URL: "https://Aladdin:[email protected]/index.html", | ||
dest: "some-dest", | ||
wantURL: "https://Aladdin:[email protected]/index.html", | ||
wantSubDir: "", | ||
wantErr: nil, | ||
}, | ||
{ | ||
name: "s3 url", | ||
URL: "s3::https://s3-eu-west-1.amazonaws.com/examplecorp-terraform-modules/vpc.zip", | ||
dest: "some-dest", | ||
wantURL: "s3::https://s3-eu-west-1.amazonaws.com/examplecorp-terraform-modules/vpc.zip", | ||
wantSubDir: "", | ||
wantErr: nil, | ||
}, | ||
{ | ||
name: "gcs url", | ||
URL: "gcs::https://www.googleapis.com/storage/v1/modules", | ||
dest: "some-dest", | ||
wantURL: "gcs::https://www.googleapis.com/storage/v1/modules", | ||
wantSubDir: "", | ||
wantErr: nil, | ||
}, | ||
} | ||
|
||
for _, tt := range table { | ||
g := NewGoGetter() | ||
gotURL, gotSubDir, gotErr := g.GetURLSubDir(tt.URL, tt.dest) | ||
if !reflect.DeepEqual(gotURL, tt.wantURL) { | ||
t.Errorf("url got: '%v', want: '%v'", gotURL, tt.wantURL) | ||
} | ||
if !reflect.DeepEqual(gotSubDir, tt.wantSubDir) { | ||
t.Errorf("url got: '%v', want: '%v'", gotSubDir, tt.wantSubDir) | ||
} | ||
if !reflect.DeepEqual(gotErr, tt.wantErr) { | ||
t.Errorf("url got: '%v', want: '%v'", gotErr, tt.wantErr) | ||
} | ||
} | ||
} |