-
Notifications
You must be signed in to change notification settings - Fork 5
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
1 parent
1a89eb1
commit 6e5d1e9
Showing
5 changed files
with
100 additions
and
48 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,45 @@ | ||
package test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/jessepeterson/kmfddm/ddm" | ||
"github.com/jessepeterson/kmfddm/http/api" | ||
) | ||
|
||
const testDecl = `{ | ||
"Type": "com.apple.configuration.management.test", | ||
"Payload": { | ||
"Echo": "Foo" | ||
}, | ||
"Identifier": "test_golang_9e6a3aa7-5e4b-4d38-aacf-0f8058b2a899" | ||
}` | ||
|
||
type allTestStorage interface { | ||
setAndDeclStorage | ||
api.EnrollmentAPIStorage | ||
} | ||
|
||
func TestBasic(t *testing.T, storage allTestStorage, ctx context.Context) { | ||
decl, err := ddm.ParseDeclaration([]byte(testDecl)) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
t.Run("StoreDeclaration", func(t *testing.T) { | ||
testStoreDeclaration(t, storage, ctx, decl) | ||
}) | ||
|
||
t.Run("TestSet", func(t *testing.T) { | ||
testSet(t, storage, ctx, decl, "test_golang_set1") | ||
}) | ||
|
||
t.Run("TestEnrollmentSets", func(t *testing.T) { | ||
testEnrollments(t, storage, ctx, "455399EA-4C94-4FA1-A87A-85A6CFEC4932", "test_golang_set1") | ||
}) | ||
|
||
t.Run("DeleteDeclaration", func(t *testing.T) { | ||
testDeleteDeclaration(t, storage, ctx, decl.Identifier) | ||
}) | ||
} |
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,54 @@ | ||
package test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/jessepeterson/kmfddm/http/api" | ||
) | ||
|
||
func testEnrollments(t *testing.T, storage api.EnrollmentAPIStorage, ctx context.Context, enrollmentID, setName string) { | ||
// associate | ||
_, err := storage.StoreEnrollmentSet(ctx, enrollmentID, setName) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
// find ref | ||
setNames, err := storage.RetrieveEnrollmentSets(ctx, enrollmentID) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
found := false | ||
for _, v := range setNames { | ||
if v == setName { | ||
found = true | ||
break | ||
} | ||
} | ||
if !found { | ||
t.Error("set name not found in enrollment sets (should exist)") | ||
} | ||
|
||
// dissociate | ||
_, err = storage.RemoveEnrollmentSet(ctx, enrollmentID, setName) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
// verify no ref | ||
setNames, err = storage.RetrieveEnrollmentSets(ctx, enrollmentID) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
found = false | ||
for _, v := range setNames { | ||
if v == setName { | ||
found = true | ||
break | ||
} | ||
} | ||
if found { | ||
t.Error("set name found in enrollment sets (should not exist)") | ||
} | ||
} |
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