-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from riweston/fix/add-tests
- Loading branch information
Showing
8 changed files
with
195 additions
and
47 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
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
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,29 @@ | ||
// +build !integration | ||
|
||
package aztx_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/google/uuid" | ||
"github.com/riweston/aztx/cmd/aztx" | ||
) | ||
|
||
func TestReadFile(t *testing.T) { | ||
value := aztx.ReadAzureProfile("azureProfile.json") | ||
equals(t, "Test Subscription 1", value.Subscriptions[0].Name) | ||
} | ||
|
||
func TestWriteFile(t *testing.T) { | ||
inputFile := aztx.ReadAzureProfile("azureProfile.json") | ||
uuid, err := uuid.Parse("9e7969ef-4cb8-4a2d-959f-bfdaae452a3d") | ||
if err != nil { | ||
panic(err) | ||
} | ||
outFile := aztx.WriteAzureProfile(inputFile, uuid, "azureProfile_test.json") | ||
ok(t, outFile) | ||
value := aztx.ReadAzureProfile("azureProfile_test.json") | ||
equals(t, true, value.Subscriptions[0].IsDefault) | ||
equals(t, false, value.Subscriptions[1].IsDefault) | ||
equals(t, false, value.Subscriptions[2].IsDefault) | ||
} |
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,47 @@ | ||
{ | ||
"installationId": "e960b7cc-c5d9-11ea-a6f5-00155d82a4f4", | ||
"subscriptions": [ | ||
{ | ||
"id": "9e7969ef-4cb8-4a2d-959f-bfdaae452a3d", | ||
"name": "Test Subscription 1", | ||
"state": "Enabled", | ||
"user": { | ||
"name": "First Last", | ||
"type": "user" | ||
}, | ||
"isDefault": false, | ||
"tenantId": "9e7969ef-4cb8-4a2d-959f-bfdaae452a3d", | ||
"environmentName": "AzureCloud", | ||
"homeTenantId": "9e7969ef-4cb8-4a2d-959f-bfdaae452a3d", | ||
"managedByTenants": [] | ||
}, | ||
{ | ||
"id": "9bb28eee-ebaa-442a-83ba-5511810fb151", | ||
"name": "Test Subscription 2", | ||
"state": "Enabled", | ||
"user": { | ||
"name": "First Last", | ||
"type": "user" | ||
}, | ||
"isDefault": false, | ||
"tenantId": "9bb28eee-ebaa-442a-83ba-5511810fb151", | ||
"environmentName": "AzureCloud", | ||
"homeTenantId": "9bb28eee-ebaa-442a-83ba-5511810fb151", | ||
"managedByTenants": [] | ||
}, | ||
{ | ||
"id": "8fff24dd-2842-4dbb-8a66-1410c7bc231f", | ||
"name": "Test Subscription 3", | ||
"state": "Enabled", | ||
"user": { | ||
"name": "First Last", | ||
"type": "user" | ||
}, | ||
"isDefault": false, | ||
"tenantId": "8fff24dd-2842-4dbb-8a66-1410c7bc231f", | ||
"environmentName": "AzureCloud", | ||
"homeTenantId": "8fff24dd-2842-4dbb-8a66-1410c7bc231f", | ||
"managedByTenants": [] | ||
} | ||
] | ||
} |
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,36 @@ | ||
package aztx_test | ||
|
||
import ( | ||
"fmt" | ||
"path/filepath" | ||
"reflect" | ||
"runtime" | ||
"testing" | ||
) | ||
|
||
// assert fails the test if the condition is false. | ||
func assert(tb testing.TB, condition bool, msg string, v ...interface{}) { | ||
if !condition { | ||
_, file, line, _ := runtime.Caller(1) | ||
fmt.Printf("\033[31m%s:%d: "+msg+"\033[39m\n\n", append([]interface{}{filepath.Base(file), line}, v...)...) | ||
tb.FailNow() | ||
} | ||
} | ||
|
||
// ok fails the test if an err is not nil. | ||
func ok(tb testing.TB, err error) { | ||
if err != nil { | ||
_, file, line, _ := runtime.Caller(1) | ||
fmt.Printf("\033[31m%s:%d: unexpected error: %s\033[39m\n\n", filepath.Base(file), line, err.Error()) | ||
tb.FailNow() | ||
} | ||
} | ||
|
||
// equals fails the test if exp is not equal to act. | ||
func equals(tb testing.TB, exp interface{}, act interface{}) { | ||
if !reflect.DeepEqual(exp, act) { | ||
_, file, line, _ := runtime.Caller(1) | ||
fmt.Printf("\033[31m%s:%d:\n\n\texp: %#v\n\n\tgot: %#v\033[39m\n\n", filepath.Base(file), line, exp, act) | ||
tb.FailNow() | ||
} | ||
} |