Thanks to visit codestin.com
Credit goes to github.com

Skip to content

test(coderd/database/dbauthz): compare outputs with cmp #16161

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 20, 2025

Conversation

mafredri
Copy link
Member

This produces a more readable diff than that of the assert library.

After:

--- FAIL: TestMethodTestSuite (0.01s)
    setup_test.go:80: Skipping method "AcquireLock": Not relevant
    setup_test.go:80: Skipping method "InTx": Not relevant
    setup_test.go:80: Skipping method "PGLocks": Not relevant
    setup_test.go:80: Skipping method "Ping": Not relevant
    setup_test.go:80: Skipping method "TryAcquireLock": Not relevant
    setup_test.go:80: Skipping method "Wrappers": Not relevant
    --- FAIL: TestMethodTestSuite/TestExtraMethods (0.00s)
        --- FAIL: TestMethodTestSuite/TestExtraMethods/GetProvisionerJobsByOrganizationAndStatusWithQueuePositionAndProvisioner (0.00s)
            --- FAIL: TestMethodTestSuite/TestExtraMethods/GetProvisionerJobsByOrganizationAndStatusWithQueuePositionAndProvisioner/Success (0.00s)
                setup_test.go:205:
                    	Error Trace:	/home/coder/coder/coderd/database/dbauthz/setup_test.go:205
                    	            				/home/coder/.local/go/pkg/mod/github.com/stretchr/[email protected]/suite/suite.go:115
                    	Error:      	compare outputs failed
                    	Test:       	TestMethodTestSuite/TestExtraMethods/GetProvisionerJobsByOrganizationAndStatusWithQueuePositionAndProvisioner/Success
                    	Messages:   	method "GetProvisionerJobsByOrganizationAndStatusWithQueuePositionAndProvisioner" returned unexpected output 0 (-want +got):
                    	            	  []database.GetProvisionerJobsByOrganizationAndStatusWithQueuePositionAndProvisionerRow{
                    	            	  	{
                    	            	  		ProvisionerJob: database.ProvisionerJob{
                    	            	  			... // 5 identical fields
                    	            	  			CompletedAt: {},
                    	            	  			Error:       {},
                    	            	  			OrganizationID: uuid.UUID{
                    	            	- 				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                    	            	+ 				0x3c, 0x73, 0x64, 0xe4, 0x17, 0x3b, 0x49, 0x2c, 0x80, 0x96, 0x0f, 0x1e, 0x3d, 0x02, 0x26, 0x37,
                    	            	  			},
                    	            	  			InitiatorID: {0x48, 0x1f, 0x5f, 0xaf, ...},
                    	            	  			Provisioner: "echo",
                    	            	  			... // 9 identical fields
                    	            	  		},
                    	            	  		QueuePosition:    2,
                    	            	  		QueueSize:        2,
                    	            	  		AvailableWorkers: nil,
                    	            	  	},
                    	            	+ 	{
                    	            	+ 		ProvisionerJob: database.ProvisionerJob{
                    	            	+ 			ID:             s"f494b47c-c149-409e-b5e2-a4f35ed4934a",
                    	            	+ 			CreatedAt:      s"2025-01-16 13:48:11.140543 +0000 UTC",
                    	            	+ 			UpdatedAt:      s"2025-01-16 13:48:11.140543 +0000 UTC",
                    	            	+ 			OrganizationID: s"3c7364e4-173b-492c-8096-0f1e3d022637",
                    	            	+ 			InitiatorID:    s"1e31c809-5d01-4aee-82f9-b851039e7201",
                    	            	+ 			Provisioner:    "echo",
                    	            	+ 			StorageMethod:  "file",
                    	            	+ 			Type:           "template_version_import",
                    	            	+ 			...
                    	            	+ 		},
                    	            	+ 		QueuePosition: 1,
                    	            	+ 		QueueSize:     2,
                    	            	+ 	},
                    	            	  }
FAIL
FAIL	github.com/coder/coder/v2/coderd/database/dbauthz	0.046s
FAIL

Before (hard to parse):

--- FAIL: TestMethodTestSuite (0.01s)
    setup_test.go:79: Skipping method "AcquireLock": Not relevant
    setup_test.go:79: Skipping method "InTx": Not relevant
    setup_test.go:79: Skipping method "PGLocks": Not relevant
    setup_test.go:79: Skipping method "Ping": Not relevant
    setup_test.go:79: Skipping method "TryAcquireLock": Not relevant
    setup_test.go:79: Skipping method "Wrappers": Not relevant
    --- FAIL: TestMethodTestSuite/TestExtraMethods (0.00s)
        --- FAIL: TestMethodTestSuite/TestExtraMethods/GetProvisionerJobsByOrganizationAndStatusWithQueuePositionAndProvisioner (0.00s)
            --- FAIL: TestMethodTestSuite/TestExtraMethods/GetProvisionerJobsByOrganizationAndStatusWithQueuePositionAndProvisioner/Success (0.00s)
                setup_test.go:207:
                    	Error Trace:	/home/coder/coder/coderd/database/dbauthz/setup_test.go:207
                    	            				/home/coder/.local/go/pkg/mod/github.com/stretchr/[email protected]/suite/suite.go:115
                    	Error:      	elements differ

                    	            	extra elements in list A:
                    	            	([]interface {}) (len=1) {
                    	            	 (database.GetProvisionerJobsByOrganizationAndStatusWithQueuePositionAndProvisionerRow) {
                    	            	  ProvisionerJob: (database.ProvisionerJob) {
                    	            	   ID: (uuid.UUID) (len=16) {
                    	            	    00000000  50 f1 fb 9f 9e 38 45 52  b8 5a 10 72 6b f5 4e 64  |P....8ER.Z.rk.Nd|
                    	            	   },
                    	            	   CreatedAt: (time.Time) {
                    	            	    wall: (uint64) 868000000,
                    	            	    ext: (int64) 63872632120,
                    	            	    loc: (*time.Location)(<nil>)
                    	            	   },
                    	            	   UpdatedAt: (time.Time) {
                    	            	    wall: (uint64) 868000000,
                    	            	    ext: (int64) 63872632120,
                    	            	    loc: (*time.Location)(<nil>)
                    	            	   },
                    	            	   StartedAt: (sql.NullTime) {
                    	            	    Time: (time.Time) {
                    	            	     wall: (uint64) 0,
                    	            	     ext: (int64) 0,
                    	            	     loc: (*time.Location)(<nil>)
                    	            	    },
                    	            	    Valid: (bool) false
                    	            	   },
                    	            	   CanceledAt: (sql.NullTime) {
                    	            	    Time: (time.Time) {
                    	            	     wall: (uint64) 0,
                    	            	     ext: (int64) 0,
                    	            	     loc: (*time.Location)(<nil>)
                    	            	    },
                    	            	    Valid: (bool) false
                    	            	   },
                    	            	   CompletedAt: (sql.NullTime) {
                    	            	    Time: (time.Time) {
                    	            	     wall: (uint64) 0,
                    	            	     ext: (int64) 0,
                    	            	     loc: (*time.Location)(<nil>)
                    	            	    },
                    	            	    Valid: (bool) false
                    	            	   },
                    	            	   Error: (sql.NullString) {
                    	            	    String: (string) "",
                    	            	    Valid: (bool) false
                    	            	   },
                    	            	   OrganizationID: (uuid.UUID) (len=16) {
                    	            	    00000000  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
                    	            	   },
                    	            	   InitiatorID: (uuid.UUID) (len=16) {
                    	            	    00000000  1f 3a f2 fd c5 65 49 28  b2 45 92 2f 5c 44 d1 4a  |.:...eI(.E./\D.J|
                    	            	   },
                    	            	   Provisioner: (database.ProvisionerType) (len=4) "echo",
                    	            	   StorageMethod: (database.ProvisionerStorageMethod) (len=4) "file",
                    	            	   Type: (database.ProvisionerJobType) (len=15) "workspace_build",
                    	            	   Input: (json.RawMessage) (len=61) {
                    	            	    00000000  7b 22 77 6f 72 6b 73 70  61 63 65 5f 62 75 69 6c  |{"workspace_buil|
                    	            	    00000010  64 5f 69 64 22 3a 22 64  62 38 33 64 31 36 61 2d  |d_id":"db83d16a-|
                    	            	    00000020  65 62 33 36 2d 34 32 34  30 2d 62 34 30 36 2d 33  |eb36-4240-b406-3|
                    	            	    00000030  63 36 35 31 34 62 64 35  31 36 39 22 7d           |c6514bd5169"}|
                    	            	   },
                    	            	   WorkerID: (uuid.NullUUID) {
                    	            	    UUID: (uuid.UUID) (len=16) {
                    	            	     00000000  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
                    	            	    },
                    	            	    Valid: (bool) false
                    	            	   },
                    	            	   FileID: (uuid.UUID) (len=16) {
                    	            	    00000000  35 7b 4e f8 7b a5 4d c0  9d 32 c3 11 4d 80 b4 3e  |5{N.{.M..2..M..>|
                    	            	   },
                    	            	   Tags: (database.StringMap) (len=1) {
                    	            	    (string) (len=5) "scope": (string) (len=12) "organization"
                    	            	   },
                    	            	   ErrorCode: (sql.NullString) {
                    	            	    String: (string) "",
                    	            	    Valid: (bool) false
                    	            	   },
                    	            	   TraceMetadata: (pqtype.NullRawMessage) {
                    	            	    RawMessage: (json.RawMessage) <nil>,
                    	            	    Valid: (bool) false
                    	            	   },
                    	            	   JobStatus: (database.ProvisionerJobStatus) (len=7) "pending"
                    	            	  },
                    	            	  QueuePosition: (int64) 2,
                    	            	  QueueSize: (int64) 2,
                    	            	  AvailableWorkers: ([]uuid.UUID) <nil>
                    	            	 }
                    	            	}


                    	            	extra elements in list B:
                    	            	([]interface {}) (len=2) {
                    	            	 (database.GetProvisionerJobsByOrganizationAndStatusWithQueuePositionAndProvisionerRow) {
                    	            	  ProvisionerJob: (database.ProvisionerJob) {
                    	            	   ID: (uuid.UUID) (len=16) {
                    	            	    00000000  50 f1 fb 9f 9e 38 45 52  b8 5a 10 72 6b f5 4e 64  |P....8ER.Z.rk.Nd|
                    	            	   },
                    	            	   CreatedAt: (time.Time) {
                    	            	    wall: (uint64) 868000000,
                    	            	    ext: (int64) 63872632120,
                    	            	    loc: (*time.Location)(<nil>)
                    	            	   },
                    	            	   UpdatedAt: (time.Time) {
                    	            	    wall: (uint64) 868000000,
                    	            	    ext: (int64) 63872632120,
                    	            	    loc: (*time.Location)(<nil>)
                    	            	   },
                    	            	   StartedAt: (sql.NullTime) {
                    	            	    Time: (time.Time) {
                    	            	     wall: (uint64) 0,
                    	            	     ext: (int64) 0,
                    	            	     loc: (*time.Location)(<nil>)
                    	            	    },
                    	            	    Valid: (bool) false
                    	            	   },
                    	            	   CanceledAt: (sql.NullTime) {
                    	            	    Time: (time.Time) {
                    	            	     wall: (uint64) 0,
                    	            	     ext: (int64) 0,
                    	            	     loc: (*time.Location)(<nil>)
                    	            	    },
                    	            	    Valid: (bool) false
                    	            	   },
                    	            	   CompletedAt: (sql.NullTime) {
                    	            	    Time: (time.Time) {
                    	            	     wall: (uint64) 0,
                    	            	     ext: (int64) 0,
                    	            	     loc: (*time.Location)(<nil>)
                    	            	    },
                    	            	    Valid: (bool) false
                    	            	   },
                    	            	   Error: (sql.NullString) {
                    	            	    String: (string) "",
                    	            	    Valid: (bool) false
                    	            	   },
                    	            	   OrganizationID: (uuid.UUID) (len=16) {
                    	            	    00000000  70 81 ae 72 a4 69 42 84  b6 c0 6f af 85 a0 06 10  |p..r.iB...o.....|
                    	            	   },
                    	            	   InitiatorID: (uuid.UUID) (len=16) {
                    	            	    00000000  1f 3a f2 fd c5 65 49 28  b2 45 92 2f 5c 44 d1 4a  |.:...eI(.E./\D.J|
                    	            	   },
                    	            	   Provisioner: (database.ProvisionerType) (len=4) "echo",
                    	            	   StorageMethod: (database.ProvisionerStorageMethod) (len=4) "file",
                    	            	   Type: (database.ProvisionerJobType) (len=15) "workspace_build",
                    	            	   Input: (json.RawMessage) (len=61) {
                    	            	    00000000  7b 22 77 6f 72 6b 73 70  61 63 65 5f 62 75 69 6c  |{"workspace_buil|
                    	            	    00000010  64 5f 69 64 22 3a 22 64  62 38 33 64 31 36 61 2d  |d_id":"db83d16a-|
                    	            	    00000020  65 62 33 36 2d 34 32 34  30 2d 62 34 30 36 2d 33  |eb36-4240-b406-3|
                    	            	    00000030  63 36 35 31 34 62 64 35  31 36 39 22 7d           |c6514bd5169"}|
                    	            	   },
                    	            	   WorkerID: (uuid.NullUUID) {
                    	            	    UUID: (uuid.UUID) (len=16) {
                    	            	     00000000  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
                    	            	    },
                    	            	    Valid: (bool) false
                    	            	   },
                    	            	   FileID: (uuid.UUID) (len=16) {
                    	            	    00000000  35 7b 4e f8 7b a5 4d c0  9d 32 c3 11 4d 80 b4 3e  |5{N.{.M..2..M..>|
                    	            	   },
                    	            	   Tags: (database.StringMap) (len=1) {
                    	            	    (string) (len=5) "scope": (string) (len=12) "organization"
                    	            	   },
                    	            	   ErrorCode: (sql.NullString) {
                    	            	    String: (string) "",
                    	            	    Valid: (bool) false
                    	            	   },
                    	            	   TraceMetadata: (pqtype.NullRawMessage) {
                    	            	    RawMessage: (json.RawMessage) <nil>,
                    	            	    Valid: (bool) false
                    	            	   },
                    	            	   JobStatus: (database.ProvisionerJobStatus) (len=7) "pending"
                    	            	  },
                    	            	  QueuePosition: (int64) 2,
                    	            	  QueueSize: (int64) 2,
                    	            	  AvailableWorkers: ([]uuid.UUID) <nil>
                    	            	 },
                    	            	 (database.GetProvisionerJobsByOrganizationAndStatusWithQueuePositionAndProvisionerRow) {
                    	            	  ProvisionerJob: (database.ProvisionerJob) {
                    	            	   ID: (uuid.UUID) (len=16) {
                    	            	    00000000  83 cb 01 26 93 7e 4d e7  80 a0 cc a9 50 ad 3a b5  |...&.~M.....P.:.|
                    	            	   },
                    	            	   CreatedAt: (time.Time) {
                    	            	    wall: (uint64) 867959000,
                    	            	    ext: (int64) 63872632120,
                    	            	    loc: (*time.Location)(<nil>)
                    	            	   },
                    	            	   UpdatedAt: (time.Time) {
                    	            	    wall: (uint64) 867959000,
                    	            	    ext: (int64) 63872632120,
                    	            	    loc: (*time.Location)(<nil>)
                    	            	   },
                    	            	   StartedAt: (sql.NullTime) {
                    	            	    Time: (time.Time) {
                    	            	     wall: (uint64) 0,
                    	            	     ext: (int64) 0,
                    	            	     loc: (*time.Location)(<nil>)
                    	            	    },
                    	            	    Valid: (bool) false
                    	            	   },
                    	            	   CanceledAt: (sql.NullTime) {
                    	            	    Time: (time.Time) {
                    	            	     wall: (uint64) 0,
                    	            	     ext: (int64) 0,
                    	            	     loc: (*time.Location)(<nil>)
                    	            	    },
                    	            	    Valid: (bool) false
                    	            	   },
                    	            	   CompletedAt: (sql.NullTime) {
                    	            	    Time: (time.Time) {
                    	            	     wall: (uint64) 0,
                    	            	     ext: (int64) 0,
                    	            	     loc: (*time.Location)(<nil>)
                    	            	    },
                    	            	    Valid: (bool) false
                    	            	   },
                    	            	   Error: (sql.NullString) {
                    	            	    String: (string) "",
                    	            	    Valid: (bool) false
                    	            	   },
                    	            	   OrganizationID: (uuid.UUID) (len=16) {
                    	            	    00000000  70 81 ae 72 a4 69 42 84  b6 c0 6f af 85 a0 06 10  |p..r.iB...o.....|
                    	            	   },
                    	            	   InitiatorID: (uuid.UUID) (len=16) {
                    	            	    00000000  bc fd a8 93 c7 8e 4c c7  a3 55 7c dd ff 38 ca 20  |......L..U|..8. |
                    	            	   },
                    	            	   Provisioner: (database.ProvisionerType) (len=4) "echo",
                    	            	   StorageMethod: (database.ProvisionerStorageMethod) (len=4) "file",
                    	            	   Type: (database.ProvisionerJobType) (len=23) "template_version_import",
                    	            	   Input: (json.RawMessage) (len=62) {
                    	            	    00000000  7b 22 74 65 6d 70 6c 61  74 65 5f 76 65 72 73 69  |{"template_versi|
                    	            	    00000010  6f 6e 5f 69 64 22 3a 22  62 62 36 62 30 61 64 65  |on_id":"bb6b0ade|
                    	            	    00000020  2d 32 30 63 38 2d 34 66  36 39 2d 39 61 66 31 2d  |-20c8-4f69-9af1-|
                    	            	    00000030  38 35 66 61 36 34 33 38  32 32 31 38 22 7d        |85fa64382218"}|
                    	            	   },
                    	            	   WorkerID: (uuid.NullUUID) {
                    	            	    UUID: (uuid.UUID) (len=16) {
                    	            	     00000000  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
                    	            	    },
                    	            	    Valid: (bool) false
                    	            	   },
                    	            	   FileID: (uuid.UUID) (len=16) {
                    	            	    00000000  be 72 0a 61 64 e1 40 ec  8d 98 85 1c 5a 2c 50 dc  |[email protected],P.|
                    	            	   },
                    	            	   Tags: (database.StringMap) (len=1) {
                    	            	    (string) (len=5) "scope": (string) (len=12) "organization"
                    	            	   },
                    	            	   ErrorCode: (sql.NullString) {
                    	            	    String: (string) "",
                    	            	    Valid: (bool) false
                    	            	   },
                    	            	   TraceMetadata: (pqtype.NullRawMessage) {
                    	            	    RawMessage: (json.RawMessage) <nil>,
                    	            	    Valid: (bool) false
                    	            	   },
                    	            	   JobStatus: (database.ProvisionerJobStatus) (len=7) "pending"
                    	            	  },
                    	            	  QueuePosition: (int64) 1,
                    	            	  QueueSize: (int64) 2,
                    	            	  AvailableWorkers: ([]uuid.UUID) <nil>
                    	            	 }
                    	            	}


                    	            	listA:
                    	            	([]database.GetProvisionerJobsByOrganizationAndStatusWithQueuePositionAndProvisionerRow) (len=1) {
                    	            	 (database.GetProvisionerJobsByOrganizationAndStatusWithQueuePositionAndProvisionerRow) {
                    	            	  ProvisionerJob: (database.ProvisionerJob) {
                    	            	   ID: (uuid.UUID) (len=16) {
                    	            	    00000000  50 f1 fb 9f 9e 38 45 52  b8 5a 10 72 6b f5 4e 64  |P....8ER.Z.rk.Nd|
                    	            	   },
                    	            	   CreatedAt: (time.Time) {
                    	            	    wall: (uint64) 868000000,
                    	            	    ext: (int64) 63872632120,
                    	            	    loc: (*time.Location)(<nil>)
                    	            	   },
                    	            	   UpdatedAt: (time.Time) {
                    	            	    wall: (uint64) 868000000,
                    	            	    ext: (int64) 63872632120,
                    	            	    loc: (*time.Location)(<nil>)
                    	            	   },
                    	            	   StartedAt: (sql.NullTime) {
                    	            	    Time: (time.Time) {
                    	            	     wall: (uint64) 0,
                    	            	     ext: (int64) 0,
                    	            	     loc: (*time.Location)(<nil>)
                    	            	    },
                    	            	    Valid: (bool) false
                    	            	   },
                    	            	   CanceledAt: (sql.NullTime) {
                    	            	    Time: (time.Time) {
                    	            	     wall: (uint64) 0,
                    	            	     ext: (int64) 0,
                    	            	     loc: (*time.Location)(<nil>)
                    	            	    },
                    	            	    Valid: (bool) false
                    	            	   },
                    	            	   CompletedAt: (sql.NullTime) {
                    	            	    Time: (time.Time) {
                    	            	     wall: (uint64) 0,
                    	            	     ext: (int64) 0,
                    	            	     loc: (*time.Location)(<nil>)
                    	            	    },
                    	            	    Valid: (bool) false
                    	            	   },
                    	            	   Error: (sql.NullString) {
                    	            	    String: (string) "",
                    	            	    Valid: (bool) false
                    	            	   },
                    	            	   OrganizationID: (uuid.UUID) (len=16) {
                    	            	    00000000  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
                    	            	   },
                    	            	   InitiatorID: (uuid.UUID) (len=16) {
                    	            	    00000000  1f 3a f2 fd c5 65 49 28  b2 45 92 2f 5c 44 d1 4a  |.:...eI(.E./\D.J|
                    	            	   },
                    	            	   Provisioner: (database.ProvisionerType) (len=4) "echo",
                    	            	   StorageMethod: (database.ProvisionerStorageMethod) (len=4) "file",
                    	            	   Type: (database.ProvisionerJobType) (len=15) "workspace_build",
                    	            	   Input: (json.RawMessage) (len=61) {
                    	            	    00000000  7b 22 77 6f 72 6b 73 70  61 63 65 5f 62 75 69 6c  |{"workspace_buil|
                    	            	    00000010  64 5f 69 64 22 3a 22 64  62 38 33 64 31 36 61 2d  |d_id":"db83d16a-|
                    	            	    00000020  65 62 33 36 2d 34 32 34  30 2d 62 34 30 36 2d 33  |eb36-4240-b406-3|
                    	            	    00000030  63 36 35 31 34 62 64 35  31 36 39 22 7d           |c6514bd5169"}|
                    	            	   },
                    	            	   WorkerID: (uuid.NullUUID) {
                    	            	    UUID: (uuid.UUID) (len=16) {
                    	            	     00000000  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
                    	            	    },
                    	            	    Valid: (bool) false
                    	            	   },
                    	            	   FileID: (uuid.UUID) (len=16) {
                    	            	    00000000  35 7b 4e f8 7b a5 4d c0  9d 32 c3 11 4d 80 b4 3e  |5{N.{.M..2..M..>|
                    	            	   },
                    	            	   Tags: (database.StringMap) (len=1) {
                    	            	    (string) (len=5) "scope": (string) (len=12) "organization"
                    	            	   },
                    	            	   ErrorCode: (sql.NullString) {
                    	            	    String: (string) "",
                    	            	    Valid: (bool) false
                    	            	   },
                    	            	   TraceMetadata: (pqtype.NullRawMessage) {
                    	            	    RawMessage: (json.RawMessage) <nil>,
                    	            	    Valid: (bool) false
                    	            	   },
                    	            	   JobStatus: (database.ProvisionerJobStatus) (len=7) "pending"
                    	            	  },
                    	            	  QueuePosition: (int64) 2,
                    	            	  QueueSize: (int64) 2,
                    	            	  AvailableWorkers: ([]uuid.UUID) <nil>
                    	            	 }
                    	            	}


                    	            	listB:
                    	            	([]database.GetProvisionerJobsByOrganizationAndStatusWithQueuePositionAndProvisionerRow) (len=2) {
                    	            	 (database.GetProvisionerJobsByOrganizationAndStatusWithQueuePositionAndProvisionerRow) {
                    	            	  ProvisionerJob: (database.ProvisionerJob) {
                    	            	   ID: (uuid.UUID) (len=16) {
                    	            	    00000000  50 f1 fb 9f 9e 38 45 52  b8 5a 10 72 6b f5 4e 64  |P....8ER.Z.rk.Nd|
                    	            	   },
                    	            	   CreatedAt: (time.Time) {
                    	            	    wall: (uint64) 868000000,
                    	            	    ext: (int64) 63872632120,
                    	            	    loc: (*time.Location)(<nil>)
                    	            	   },
                    	            	   UpdatedAt: (time.Time) {
                    	            	    wall: (uint64) 868000000,
                    	            	    ext: (int64) 63872632120,
                    	            	    loc: (*time.Location)(<nil>)
                    	            	   },
                    	            	   StartedAt: (sql.NullTime) {
                    	            	    Time: (time.Time) {
                    	            	     wall: (uint64) 0,
                    	            	     ext: (int64) 0,
                    	            	     loc: (*time.Location)(<nil>)
                    	            	    },
                    	            	    Valid: (bool) false
                    	            	   },
                    	            	   CanceledAt: (sql.NullTime) {
                    	            	    Time: (time.Time) {
                    	            	     wall: (uint64) 0,
                    	            	     ext: (int64) 0,
                    	            	     loc: (*time.Location)(<nil>)
                    	            	    },
                    	            	    Valid: (bool) false
                    	            	   },
                    	            	   CompletedAt: (sql.NullTime) {
                    	            	    Time: (time.Time) {
                    	            	     wall: (uint64) 0,
                    	            	     ext: (int64) 0,
                    	            	     loc: (*time.Location)(<nil>)
                    	            	    },
                    	            	    Valid: (bool) false
                    	            	   },
                    	            	   Error: (sql.NullString) {
                    	            	    String: (string) "",
                    	            	    Valid: (bool) false
                    	            	   },
                    	            	   OrganizationID: (uuid.UUID) (len=16) {
                    	            	    00000000  70 81 ae 72 a4 69 42 84  b6 c0 6f af 85 a0 06 10  |p..r.iB...o.....|
                    	            	   },
                    	            	   InitiatorID: (uuid.UUID) (len=16) {
                    	            	    00000000  1f 3a f2 fd c5 65 49 28  b2 45 92 2f 5c 44 d1 4a  |.:...eI(.E./\D.J|
                    	            	   },
                    	            	   Provisioner: (database.ProvisionerType) (len=4) "echo",
                    	            	   StorageMethod: (database.ProvisionerStorageMethod) (len=4) "file",
                    	            	   Type: (database.ProvisionerJobType) (len=15) "workspace_build",
                    	            	   Input: (json.RawMessage) (len=61) {
                    	            	    00000000  7b 22 77 6f 72 6b 73 70  61 63 65 5f 62 75 69 6c  |{"workspace_buil|
                    	            	    00000010  64 5f 69 64 22 3a 22 64  62 38 33 64 31 36 61 2d  |d_id":"db83d16a-|
                    	            	    00000020  65 62 33 36 2d 34 32 34  30 2d 62 34 30 36 2d 33  |eb36-4240-b406-3|
                    	            	    00000030  63 36 35 31 34 62 64 35  31 36 39 22 7d           |c6514bd5169"}|
                    	            	   },
                    	            	   WorkerID: (uuid.NullUUID) {
                    	            	    UUID: (uuid.UUID) (len=16) {
                    	            	     00000000  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
                    	            	    },
                    	            	    Valid: (bool) false
                    	            	   },
                    	            	   FileID: (uuid.UUID) (len=16) {
                    	            	    00000000  35 7b 4e f8 7b a5 4d c0  9d 32 c3 11 4d 80 b4 3e  |5{N.{.M..2..M..>|
                    	            	   },
                    	            	   Tags: (database.StringMap) (len=1) {
                    	            	    (string) (len=5) "scope": (string) (len=12) "organization"
                    	            	   },
                    	            	   ErrorCode: (sql.NullString) {
                    	            	    String: (string) "",
                    	            	    Valid: (bool) false
                    	            	   },
                    	            	   TraceMetadata: (pqtype.NullRawMessage) {
                    	            	    RawMessage: (json.RawMessage) <nil>,
                    	            	    Valid: (bool) false
                    	            	   },
                    	            	   JobStatus: (database.ProvisionerJobStatus) (len=7) "pending"
                    	            	  },
                    	            	  QueuePosition: (int64) 2,
                    	            	  QueueSize: (int64) 2,
                    	            	  AvailableWorkers: ([]uuid.UUID) <nil>
                    	            	 },
                    	            	 (database.GetProvisionerJobsByOrganizationAndStatusWithQueuePositionAndProvisionerRow) {
                    	            	  ProvisionerJob: (database.ProvisionerJob) {
                    	            	   ID: (uuid.UUID) (len=16) {
                    	            	    00000000  83 cb 01 26 93 7e 4d e7  80 a0 cc a9 50 ad 3a b5  |...&.~M.....P.:.|
                    	            	   },
                    	            	   CreatedAt: (time.Time) {
                    	            	    wall: (uint64) 867959000,
                    	            	    ext: (int64) 63872632120,
                    	            	    loc: (*time.Location)(<nil>)
                    	            	   },
                    	            	   UpdatedAt: (time.Time) {
                    	            	    wall: (uint64) 867959000,
                    	            	    ext: (int64) 63872632120,
                    	            	    loc: (*time.Location)(<nil>)
                    	            	   },
                    	            	   StartedAt: (sql.NullTime) {
                    	            	    Time: (time.Time) {
                    	            	     wall: (uint64) 0,
                    	            	     ext: (int64) 0,
                    	            	     loc: (*time.Location)(<nil>)
                    	            	    },
                    	            	    Valid: (bool) false
                    	            	   },
                    	            	   CanceledAt: (sql.NullTime) {
                    	            	    Time: (time.Time) {
                    	            	     wall: (uint64) 0,
                    	            	     ext: (int64) 0,
                    	            	     loc: (*time.Location)(<nil>)
                    	            	    },
                    	            	    Valid: (bool) false
                    	            	   },
                    	            	   CompletedAt: (sql.NullTime) {
                    	            	    Time: (time.Time) {
                    	            	     wall: (uint64) 0,
                    	            	     ext: (int64) 0,
                    	            	     loc: (*time.Location)(<nil>)
                    	            	    },
                    	            	    Valid: (bool) false
                    	            	   },
                    	            	   Error: (sql.NullString) {
                    	            	    String: (string) "",
                    	            	    Valid: (bool) false
                    	            	   },
                    	            	   OrganizationID: (uuid.UUID) (len=16) {
                    	            	    00000000  70 81 ae 72 a4 69 42 84  b6 c0 6f af 85 a0 06 10  |p..r.iB...o.....|
                    	            	   },
                    	            	   InitiatorID: (uuid.UUID) (len=16) {
                    	            	    00000000  bc fd a8 93 c7 8e 4c c7  a3 55 7c dd ff 38 ca 20  |......L..U|..8. |
                    	            	   },
                    	            	   Provisioner: (database.ProvisionerType) (len=4) "echo",
                    	            	   StorageMethod: (database.ProvisionerStorageMethod) (len=4) "file",
                    	            	   Type: (database.ProvisionerJobType) (len=23) "template_version_import",
                    	            	   Input: (json.RawMessage) (len=62) {
                    	            	    00000000  7b 22 74 65 6d 70 6c 61  74 65 5f 76 65 72 73 69  |{"template_versi|
                    	            	    00000010  6f 6e 5f 69 64 22 3a 22  62 62 36 62 30 61 64 65  |on_id":"bb6b0ade|
                    	            	    00000020  2d 32 30 63 38 2d 34 66  36 39 2d 39 61 66 31 2d  |-20c8-4f69-9af1-|
                    	            	    00000030  38 35 66 61 36 34 33 38  32 32 31 38 22 7d        |85fa64382218"}|
                    	            	   },
                    	            	   WorkerID: (uuid.NullUUID) {
                    	            	    UUID: (uuid.UUID) (len=16) {
                    	            	     00000000  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
                    	            	    },
                    	            	    Valid: (bool) false
                    	            	   },
                    	            	   FileID: (uuid.UUID) (len=16) {
                    	            	    00000000  be 72 0a 61 64 e1 40 ec  8d 98 85 1c 5a 2c 50 dc  |[email protected],P.|
                    	            	   },
                    	            	   Tags: (database.StringMap) (len=1) {
                    	            	    (string) (len=5) "scope": (string) (len=12) "organization"
                    	            	   },
                    	            	   ErrorCode: (sql.NullString) {
                    	            	    String: (string) "",
                    	            	    Valid: (bool) false
                    	            	   },
                    	            	   TraceMetadata: (pqtype.NullRawMessage) {
                    	            	    RawMessage: (json.RawMessage) <nil>,
                    	            	    Valid: (bool) false
                    	            	   },
                    	            	   JobStatus: (database.ProvisionerJobStatus) (len=7) "pending"
                    	            	  },
                    	            	  QueuePosition: (int64) 1,
                    	            	  QueueSize: (int64) 2,
                    	            	  AvailableWorkers: ([]uuid.UUID) <nil>
                    	            	 }
                    	            	}
                    	Test:       	TestMethodTestSuite/TestExtraMethods/GetProvisionerJobsByOrganizationAndStatusWithQueuePositionAndProvisioner/Success
                    	Messages:   	method "GetProvisionerJobsByOrganizationAndStatusWithQueuePositionAndProvisioner" returned unexpected output 0
FAIL
FAIL	github.com/coder/coder/v2/coderd/database/dbauthz	0.044s
FAIL

This produces a more readable diff than that of the assert library.
Copy link
Member

@Emyrk Emyrk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That does look way better 👍

Comment on lines 203 to 206
// Use cmp.Diff to get a nice diff of the two values.
if diff := cmp.Diff(a, b, cmpopts.EquateEmpty()); diff != "" {
s.Failf("compare outputs failed", "method %q returned unexpected output %d (-want +got):\n%s", methodName, i, diff)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing we lose though is that the order should not matter for slices.

I was using ElementsMatch before. Does different ordering now break the comparison?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point, there is cmpopts.SortSlices but it seems a bit more work to support than ElementsMatch. 🤔

TBH I'd prefer if all output from the DB was deterministic but that's a huge undertaking to fix it everywhere 😅

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, unsure on the db determinism. I do recall in the past our dbmem and pg implementation had different orders for some listing call.

I did ElementsMatch just to avoid any potential ordering flakes. The order is not something these tests care about.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does 6d2b94d (#16161) seem acceptable?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works for me!

Might be worth throwing in one of the test util packages.

@mafredri mafredri force-pushed the mafredri/test-fix-dbauthz-element-comparison branch from 04519f6 to 7ed901b Compare January 16, 2025 16:00
@mafredri mafredri merged commit 0e8ef09 into main Jan 20, 2025
31 checks passed
@mafredri mafredri deleted the mafredri/test-fix-dbauthz-element-comparison branch January 20, 2025 09:12
@github-actions github-actions bot locked and limited conversation to collaborators Jan 20, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants