| 1 | // Copyright (C) MongoDB, Inc. 2023-present. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 4 | // not use this file except in compliance with the License. You may obtain |
| 5 | // a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | |
| 7 | package logger_testscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/internal/logger_test`/ |
| 8 | |
| 9 | import ( |
| 10 | "contextscip-go gomod github.com/golang/go/src go1.18 context/" |
| 11 | "testingscip-go gomod github.com/golang/go/src go1.18 testing/" |
| 12 | |
| 13 | "go.mongodb.org/mongo-driver/internal/assertscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/internal/assert`/" |
| 14 | "go.mongodb.org/mongo-driver/internal/loggerscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/internal/logger`/" |
| 15 | ) |
| 16 | |
| 17 | func TestContext_WithOperationNamescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/internal/logger_test`/TestContext_WithOperationName().(t *testingscip-go gomod github.com/golang/go/src go1.18 testing/.Tscip-go gomod github.com/golang/go/src go1.18 testing/T#) { |
| 18 | t.Parallelscip-go gomod github.com/golang/go/src go1.18 testing/T#Parallel().() |
| 19 | |
| 20 | tests := []struct { |
| 21 | name string |
| 22 | ctx contextscip-go gomod github.com/golang/go/src go1.18 context/.Contextscip-go gomod github.com/golang/go/src go1.18 context/Context# |
| 23 | opName string |
| 24 | ok bool |
| 25 | }{ |
| 26 | { |
| 27 | name: "simple", |
| 28 | ctx: contextscip-go gomod github.com/golang/go/src go1.18 context/.Backgroundscip-go gomod github.com/golang/go/src go1.18 context/Background().(), |
| 29 | opName: "foo", |
| 30 | ok: true, |
| 31 | }, |
| 32 | } |
| 33 | |
| 34 | for _, tt := range tests { |
| 35 | tt := tt // Capture the range variable. |
| 36 | |
| 37 | t.Runscip-go gomod github.com/golang/go/src go1.18 testing/T#Run().(tt.name, func(t *testingscip-go gomod github.com/golang/go/src go1.18 testing/.Tscip-go gomod github.com/golang/go/src go1.18 testing/T#) { |
| 38 | t.Parallelscip-go gomod github.com/golang/go/src go1.18 testing/T#Parallel().() |
| 39 | |
| 40 | ctx := loggerscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/internal/logger`/.WithOperationNamescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/internal/logger`/WithOperationName().(tt.ctx, tt.opName) |
| 41 | |
| 42 | opName, ok := loggerscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/internal/logger`/.OperationNamescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/internal/logger`/OperationName().(ctx) |
| 43 | assertscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/internal/assert`/.Equalscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/internal/assert`/Equal().(t, tt.ok, ok) |
| 44 | |
| 45 | if ok { |
| 46 | assertscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/internal/assert`/.Equalscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/internal/assert`/Equal().(t, tt.opName, opName) |
| 47 | } |
| 48 | }) |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | func TestContext_OperationNamescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/internal/logger_test`/TestContext_OperationName().(t *testingscip-go gomod github.com/golang/go/src go1.18 testing/.Tscip-go gomod github.com/golang/go/src go1.18 testing/T#) { |
| 53 | t.Parallelscip-go gomod github.com/golang/go/src go1.18 testing/T#Parallel().() |
| 54 | |
| 55 | tests := []struct { |
| 56 | name string |
| 57 | ctx contextscip-go gomod github.com/golang/go/src go1.18 context/.Contextscip-go gomod github.com/golang/go/src go1.18 context/Context# |
| 58 | opName interface{} |
| 59 | ok bool |
| 60 | }{ |
| 61 | { |
| 62 | name: "nil", |
| 63 | ctx: contextscip-go gomod github.com/golang/go/src go1.18 context/.Backgroundscip-go gomod github.com/golang/go/src go1.18 context/Background().(), |
| 64 | opName: nil, |
| 65 | ok: false, |
| 66 | }, |
| 67 | { |
| 68 | name: "string type", |
| 69 | ctx: contextscip-go gomod github.com/golang/go/src go1.18 context/.Backgroundscip-go gomod github.com/golang/go/src go1.18 context/Background().(), |
| 70 | opName: "foo", |
| 71 | ok: true, |
| 72 | }, |
| 73 | { |
| 74 | name: "non-string type", |
| 75 | ctx: contextscip-go gomod github.com/golang/go/src go1.18 context/.Backgroundscip-go gomod github.com/golang/go/src go1.18 context/Background().(), |
| 76 | opName: int32(1), |
| 77 | ok: false, |
| 78 | }, |
| 79 | } |
| 80 | |
| 81 | for _, tt := range tests { |
| 82 | tt := tt // Capture the range variable. |
| 83 | |
| 84 | t.Runscip-go gomod github.com/golang/go/src go1.18 testing/T#Run().(tt.name, func(t *testingscip-go gomod github.com/golang/go/src go1.18 testing/.Tscip-go gomod github.com/golang/go/src go1.18 testing/T#) { |
| 85 | t.Parallelscip-go gomod github.com/golang/go/src go1.18 testing/T#Parallel().() |
| 86 | |
| 87 | ctx := contextscip-go gomod github.com/golang/go/src go1.18 context/.Backgroundscip-go gomod github.com/golang/go/src go1.18 context/Background().() |
| 88 | |
| 89 | if opNameStr, ok := tt.opName.(string); ok { |
| 90 | ctx = loggerscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/internal/logger`/.WithOperationNamescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/internal/logger`/WithOperationName().(tt.ctx, opNameStr) |
| 91 | } |
| 92 | |
| 93 | opName, ok := loggerscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/internal/logger`/.OperationNamescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/internal/logger`/OperationName().(ctx) |
| 94 | assertscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/internal/assert`/.Equalscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/internal/assert`/Equal().(t, tt.ok, ok) |
| 95 | |
| 96 | if ok { |
| 97 | assertscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/internal/assert`/.Equalscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/internal/assert`/Equal().(t, tt.opName, opName) |
| 98 | } |
| 99 | }) |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | func TestContext_WithOperationIDscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/internal/logger_test`/TestContext_WithOperationID().(t *testingscip-go gomod github.com/golang/go/src go1.18 testing/.Tscip-go gomod github.com/golang/go/src go1.18 testing/T#) { |
| 104 | t.Parallelscip-go gomod github.com/golang/go/src go1.18 testing/T#Parallel().() |
| 105 | |
| 106 | tests := []struct { |
| 107 | name string |
| 108 | ctx contextscip-go gomod github.com/golang/go/src go1.18 context/.Contextscip-go gomod github.com/golang/go/src go1.18 context/Context# |
| 109 | opID int32 |
| 110 | ok bool |
| 111 | }{ |
| 112 | { |
| 113 | name: "non-zero", |
| 114 | ctx: contextscip-go gomod github.com/golang/go/src go1.18 context/.Backgroundscip-go gomod github.com/golang/go/src go1.18 context/Background().(), |
| 115 | opID: 1, |
| 116 | ok: true, |
| 117 | }, |
| 118 | } |
| 119 | |
| 120 | for _, tt := range tests { |
| 121 | tt := tt // Capture the range variable. |
| 122 | |
| 123 | t.Runscip-go gomod github.com/golang/go/src go1.18 testing/T#Run().(tt.name, func(t *testingscip-go gomod github.com/golang/go/src go1.18 testing/.Tscip-go gomod github.com/golang/go/src go1.18 testing/T#) { |
| 124 | t.Parallelscip-go gomod github.com/golang/go/src go1.18 testing/T#Parallel().() |
| 125 | |
| 126 | ctx := loggerscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/internal/logger`/.WithOperationIDscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/internal/logger`/WithOperationID().(tt.ctx, tt.opID) |
| 127 | |
| 128 | opID, ok := loggerscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/internal/logger`/.OperationIDscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/internal/logger`/OperationID().(ctx) |
| 129 | assertscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/internal/assert`/.Equalscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/internal/assert`/Equal().(t, tt.ok, ok) |
| 130 | |
| 131 | if ok { |
| 132 | assertscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/internal/assert`/.Equalscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/internal/assert`/Equal().(t, tt.opID, opID) |
| 133 | } |
| 134 | }) |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | func TestContext_OperationIDscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/internal/logger_test`/TestContext_OperationID().(t *testingscip-go gomod github.com/golang/go/src go1.18 testing/.Tscip-go gomod github.com/golang/go/src go1.18 testing/T#) { |
| 139 | t.Parallelscip-go gomod github.com/golang/go/src go1.18 testing/T#Parallel().() |
| 140 | |
| 141 | tests := []struct { |
| 142 | name string |
| 143 | ctx contextscip-go gomod github.com/golang/go/src go1.18 context/.Contextscip-go gomod github.com/golang/go/src go1.18 context/Context# |
| 144 | opID interface{} |
| 145 | ok bool |
| 146 | }{ |
| 147 | { |
| 148 | name: "nil", |
| 149 | ctx: contextscip-go gomod github.com/golang/go/src go1.18 context/.Backgroundscip-go gomod github.com/golang/go/src go1.18 context/Background().(), |
| 150 | opID: nil, |
| 151 | ok: false, |
| 152 | }, |
| 153 | { |
| 154 | name: "i32 type", |
| 155 | ctx: contextscip-go gomod github.com/golang/go/src go1.18 context/.Backgroundscip-go gomod github.com/golang/go/src go1.18 context/Background().(), |
| 156 | opID: int32(1), |
| 157 | ok: true, |
| 158 | }, |
| 159 | { |
| 160 | name: "non-i32 type", |
| 161 | ctx: contextscip-go gomod github.com/golang/go/src go1.18 context/.Backgroundscip-go gomod github.com/golang/go/src go1.18 context/Background().(), |
| 162 | opID: "foo", |
| 163 | ok: false, |
| 164 | }, |
| 165 | } |
| 166 | |
| 167 | for _, tt := range tests { |
| 168 | tt := tt // Capture the range variable. |
| 169 | |
| 170 | t.Runscip-go gomod github.com/golang/go/src go1.18 testing/T#Run().(tt.name, func(t *testingscip-go gomod github.com/golang/go/src go1.18 testing/.Tscip-go gomod github.com/golang/go/src go1.18 testing/T#) { |
| 171 | t.Parallelscip-go gomod github.com/golang/go/src go1.18 testing/T#Parallel().() |
| 172 | |
| 173 | ctx := contextscip-go gomod github.com/golang/go/src go1.18 context/.Backgroundscip-go gomod github.com/golang/go/src go1.18 context/Background().() |
| 174 | |
| 175 | if opIDI32, ok := tt.opID.(int32); ok { |
| 176 | ctx = loggerscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/internal/logger`/.WithOperationIDscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/internal/logger`/WithOperationID().(tt.ctx, opIDI32) |
| 177 | } |
| 178 | |
| 179 | opName, ok := loggerscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/internal/logger`/.OperationIDscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/internal/logger`/OperationID().(ctx) |
| 180 | assertscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/internal/assert`/.Equalscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/internal/assert`/Equal().(t, tt.ok, ok) |
| 181 | |
| 182 | if ok { |
| 183 | assertscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/internal/assert`/.Equalscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/internal/assert`/Equal().(t, tt.opID, opName) |
| 184 | } |
| 185 | }) |
| 186 | } |
| 187 | } |