-
Notifications
You must be signed in to change notification settings - Fork 245
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(brig): add tests for brig project create
- Loading branch information
1 parent
85a4cc1
commit 966fc1a
Showing
3 changed files
with
169 additions
and
26 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
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,83 @@ | ||
package commands | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
) | ||
|
||
const testProjectSecret = "./testdata/project_secret.json" | ||
|
||
func TestParseSecret(t *testing.T) { | ||
f, err := os.Open(testProjectSecret) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
defer f.Close() | ||
sec, err := parseSecret(f) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
expect := "brigade-407900363c01e6153bc1a91792055b898e20a29f1387b72a0b6f00" | ||
if sec.Name != expect { | ||
t.Fatalf("Expected name %s, got %s", expect, sec.Name) | ||
} | ||
} | ||
|
||
func TestLoadProjectConfig(t *testing.T) { | ||
proj, err := loadProjectConfig(testProjectSecret, defaultProject) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
// We just spot-check a few values. The kube package tests every field. | ||
if proj.Name != "technosophos/-whale-eyes-" { | ||
t.Error("Expected project name to be whale eyes") | ||
} | ||
if proj.Kubernetes.BuildStorageSize != "50Mi" { | ||
t.Error("Expected Kubernetes BuilStorageSize to be 50Mi") | ||
} | ||
|
||
if proj.Github.Token != "not with a bang but a whimper" { | ||
t.Errorf("Expected Github secret to be set") | ||
} | ||
|
||
if proj.Worker.PullPolicy != "Always" { | ||
t.Errorf("expected worker pull policy to be Always.") | ||
} | ||
} | ||
|
||
func TestLoadFileValidator(t *testing.T) { | ||
if err := loadFileValidator(testProjectSecret); err != nil { | ||
t.Fatal(err) | ||
} | ||
if err := loadFileValidator("sir/not/appearing/in/this/film"); err == nil { | ||
t.Fatal("expected load of non-existent file to produce an eror") | ||
} | ||
} | ||
|
||
func TestLoadFileStr(t *testing.T) { | ||
if data := loadFileStr(testProjectSecret); data == "" { | ||
t.Fatal("Data should have been loaded") | ||
} | ||
if data := loadFileStr("sir/not/appearing"); len(data) > 0 { | ||
t.Fatal("Expected empty string for nonexistent file") | ||
} | ||
} | ||
|
||
func TestIsHTTP(t *testing.T) { | ||
tests := map[string]bool{ | ||
"http://foo.bar": true, | ||
"https://foo.bar": true, | ||
"http@foo.bar": false, | ||
"": false, | ||
"HTTP://foo.bar": true, | ||
"git@foo.bar": false, | ||
"ssh://git@foo.bar": false, | ||
} | ||
|
||
for url, expect := range tests { | ||
if isHTTP(url) != expect { | ||
t.Errorf("Unexpected result for %q", url) | ||
} | ||
} | ||
} |
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,41 @@ | ||
{ | ||
"metadata": { | ||
"name": "brigade-407900363c01e6153bc1a91792055b898e20a29f1387b72a0b6f00", | ||
"creationTimestamp": null, | ||
"labels": { | ||
"app": "brigade", | ||
"component": "project", | ||
"heritage": "brigade" | ||
}, | ||
"annotations": { | ||
"projectName": "technosophos/-whale-eyes-" | ||
} | ||
}, | ||
"stringData": { | ||
"allowHostMounts": "false", | ||
"allowPrivilegedJobs": "true", | ||
"buildStorageSize": "50Mi", | ||
"cloneURL": "https://github.com/technosophos/-whale-eyes-.git", | ||
"defaultScript": "", | ||
"defaultScriptName": "", | ||
"github.baseURL": "", | ||
"github.token": "not with a bang but a whimper", | ||
"github.uploadURL": "", | ||
"imagePullSecrets": "my voice is my passport", | ||
"initGitSubmodules": "false", | ||
"kubernetes.buildStorageClass": "default", | ||
"kubernetes.cacheStorageClass": "default", | ||
"namespace": "default", | ||
"repository": "github.com/technosophos/-whale-eyes-", | ||
"secrets": "{}", | ||
"sharedSecret": "IBrakeForSeaBeasts", | ||
"sshKey": "", | ||
"vcsSidecar": "deis/git-sidecar:latest", | ||
"worker.name": "", | ||
"worker.pullPolicy": "Always", | ||
"worker.registry": "", | ||
"worker.tag": "", | ||
"workerCommand": "" | ||
}, | ||
"type": "brigade.sh/project" | ||
} |