...
1# Sequel test guide
2
3- All controllers tests are to check that all the resources we expect to be created are present in the kubernetes cluster after reconcilation.
4
5**For `sequel`, `controller_test.go` is used to set up test environment/framework, and you will write actual tests on `user_controller_test.go`**
6
7- You will set up the according test variables for your own test case and then set up your sequel
8
9- Let's use example `TestCreateBuiltInUser` from `user_controller_test.go`
10
11- First, set up the test function:
12
13
14```
15func TestCreateBuiltInUser(t *testing.T) {
16
17}
18```
19
20- Set up your test user:
21
22
23```
24 t.Skip("TODO(pa250194_ncrvoyix): fix errors")
25 namespace := uuid.New().UUID
26 usr := mockDatabaseUser("sequelbuiltinuser", namespace, backendv1.BuiltInUserType)
27
28```
29
30- Set up your sequel user name `BuiltIn User`, and add tests to verify its reconciliation status:
31
32```
33 sequelUser := f2.NewFeature("BuiltIn User").
34 Test("BuiltIn User reconciles", func(ctx f2.Context, t *testing.T) f2.Context {
35 k := ktest.FromContextT(ctx, t)
36 assert.NilError(t, k.Client.Create(ctx, usr))
37 k.WaitOn(t, k.Check(usr, kmp.IsReady()))
38 return ctx
39 }).
40 Test("Finalizer is added", func(ctx f2.Context, t *testing.T) f2.Context {
41 if controllerutil.ContainsFinalizer(usr, backendv1.SequelFinalizer) {
42 t.Error("finalizer not added to database user", spew.Sprintln(usr))
43 }
44 return ctx
45 }).
46 Test("CloudSQL User created", func(ctx f2.Context, t *testing.T) f2.Context {
47 k := ktest.FromContextT(ctx, t)
48 cloudSQLUsr := &sqlAPI.SQLUser{}
49 assert.NilError(t, k.Client.Get(ctx, types.NamespacedName{
50 Name: usr.Name,
51 Namespace: usr.Namespace,
52 }, cloudSQLUsr))
53 assert.Equal(t, cloudSQLUsr.Name, usr.Name)
54 assert.Equal(t, cloudSQLUsr.Namespace, usr.Namespace)
55 assert.Equal(t, cloudSQLUsr.Spec.Type, backendv1.BuiltInUserType)
56 testifyAssert.Empty(t, cloudSQLUsr)
57 return ctx
58 }).Feature()
59
60 f.Test(t, sequelUser)
61
62```
63
64
65# If you have any further question, please reach out to the platform team via #ncr-edge-api or #ncr-edge-backend :)
View as plain text