Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 0c62bb2

Browse files
authoredAug 19, 2022
Go1.19 is released (#1350)
1 parent ad9fa14 commit 0c62bb2

19 files changed

+226
-176
lines changed
 

‎.github/workflows/test.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ jobs:
2222
import json
2323
go = [
2424
# Keep the most recent production release at the top
25-
'1.18',
25+
'1.19',
2626
# Older production releases
27+
'1.18',
2728
'1.17',
2829
'1.16',
2930
'1.15',

‎atomic_bool.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Go MySQL Driver - A MySQL-Driver for Go's database/sql package.
2+
//
3+
// Copyright 2022 The Go-MySQL-Driver Authors. All rights reserved.
4+
//
5+
// This Source Code Form is subject to the terms of the Mozilla Public
6+
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
7+
// You can obtain one at http://mozilla.org/MPL/2.0/.
8+
//go:build go1.19
9+
// +build go1.19
10+
11+
package mysql
12+
13+
import "sync/atomic"
14+
15+
/******************************************************************************
16+
* Sync utils *
17+
******************************************************************************/
18+
19+
type atomicBool = atomic.Bool

‎atomic_bool_go118.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Go MySQL Driver - A MySQL-Driver for Go's database/sql package.
2+
//
3+
// Copyright 2022 The Go-MySQL-Driver Authors. All rights reserved.
4+
//
5+
// This Source Code Form is subject to the terms of the Mozilla Public
6+
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
7+
// You can obtain one at http://mozilla.org/MPL/2.0/.
8+
//go:build !go1.19
9+
// +build !go1.19
10+
11+
package mysql
12+
13+
import "sync/atomic"
14+
15+
/******************************************************************************
16+
* Sync utils *
17+
******************************************************************************/
18+
19+
// atomicBool is an implementation of atomic.Bool for older version of Go.
20+
// it is a wrapper around uint32 for usage as a boolean value with
21+
// atomic access.
22+
type atomicBool struct {
23+
_ noCopy
24+
value uint32
25+
}
26+
27+
// Load returns whether the current boolean value is true
28+
func (ab *atomicBool) Load() bool {
29+
return atomic.LoadUint32(&ab.value) > 0
30+
}
31+
32+
// Store sets the value of the bool regardless of the previous value
33+
func (ab *atomicBool) Store(value bool) {
34+
if value {
35+
atomic.StoreUint32(&ab.value, 1)
36+
} else {
37+
atomic.StoreUint32(&ab.value, 0)
38+
}
39+
}
40+
41+
// Swap sets the value of the bool and returns the old value.
42+
func (ab *atomicBool) Swap(value bool) bool {
43+
if value {
44+
return atomic.SwapUint32(&ab.value, 1) > 0
45+
}
46+
return atomic.SwapUint32(&ab.value, 0) > 0
47+
}

‎atomic_bool_test.go

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Go MySQL Driver - A MySQL-Driver for Go's database/sql package.
2+
//
3+
// Copyright 2022 The Go-MySQL-Driver Authors. All rights reserved.
4+
//
5+
// This Source Code Form is subject to the terms of the Mozilla Public
6+
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
7+
// You can obtain one at http://mozilla.org/MPL/2.0/.
8+
//go:build !go1.19
9+
// +build !go1.19
10+
11+
package mysql
12+
13+
import (
14+
"testing"
15+
)
16+
17+
func TestAtomicBool(t *testing.T) {
18+
var ab atomicBool
19+
if ab.Load() {
20+
t.Fatal("Expected value to be false")
21+
}
22+
23+
ab.Store(true)
24+
if ab.value != 1 {
25+
t.Fatal("Set(true) did not set value to 1")
26+
}
27+
if !ab.Load() {
28+
t.Fatal("Expected value to be true")
29+
}
30+
31+
ab.Store(true)
32+
if !ab.Load() {
33+
t.Fatal("Expected value to be true")
34+
}
35+
36+
ab.Store(false)
37+
if ab.value != 0 {
38+
t.Fatal("Set(false) did not set value to 0")
39+
}
40+
if ab.Load() {
41+
t.Fatal("Expected value to be false")
42+
}
43+
44+
ab.Store(false)
45+
if ab.Load() {
46+
t.Fatal("Expected value to be false")
47+
}
48+
if ab.Swap(false) {
49+
t.Fatal("Expected the old value to be false")
50+
}
51+
if ab.Swap(true) {
52+
t.Fatal("Expected the old value to be false")
53+
}
54+
if !ab.Load() {
55+
t.Fatal("Expected value to be true")
56+
}
57+
58+
ab.Store(true)
59+
if !ab.Load() {
60+
t.Fatal("Expected value to be true")
61+
}
62+
if !ab.Swap(true) {
63+
t.Fatal("Expected the old value to be true")
64+
}
65+
if !ab.Swap(false) {
66+
t.Fatal("Expected the old value to be true")
67+
}
68+
if ab.Load() {
69+
t.Fatal("Expected value to be false")
70+
}
71+
}

‎auth.go

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,27 +33,26 @@ var (
3333
// Note: The provided rsa.PublicKey instance is exclusively owned by the driver
3434
// after registering it and may not be modified.
3535
//
36-
// data, err := ioutil.ReadFile("mykey.pem")
37-
// if err != nil {
38-
// log.Fatal(err)
39-
// }
36+
// data, err := ioutil.ReadFile("mykey.pem")
37+
// if err != nil {
38+
// log.Fatal(err)
39+
// }
4040
//
41-
// block, _ := pem.Decode(data)
42-
// if block == nil || block.Type != "PUBLIC KEY" {
43-
// log.Fatal("failed to decode PEM block containing public key")
44-
// }
41+
// block, _ := pem.Decode(data)
42+
// if block == nil || block.Type != "PUBLIC KEY" {
43+
// log.Fatal("failed to decode PEM block containing public key")
44+
// }
4545
//
46-
// pub, err := x509.ParsePKIXPublicKey(block.Bytes)
47-
// if err != nil {
48-
// log.Fatal(err)
49-
// }
50-
//
51-
// if rsaPubKey, ok := pub.(*rsa.PublicKey); ok {
52-
// mysql.RegisterServerPubKey("mykey", rsaPubKey)
53-
// } else {
54-
// log.Fatal("not a RSA public key")
55-
// }
46+
// pub, err := x509.ParsePKIXPublicKey(block.Bytes)
47+
// if err != nil {
48+
// log.Fatal(err)
49+
// }
5650
//
51+
// if rsaPubKey, ok := pub.(*rsa.PublicKey); ok {
52+
// mysql.RegisterServerPubKey("mykey", rsaPubKey)
53+
// } else {
54+
// log.Fatal("not a RSA public key")
55+
// }
5756
func RegisterServerPubKey(name string, pubKey *rsa.PublicKey) {
5857
serverPubKeyLock.Lock()
5958
if serverPubKeyRegistry == nil {

‎collations.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ const binaryCollation = "binary"
1313

1414
// A list of available collations mapped to the internal ID.
1515
// To update this map use the following MySQL query:
16-
// SELECT COLLATION_NAME, ID FROM information_schema.COLLATIONS WHERE ID<256 ORDER BY ID
16+
//
17+
// SELECT COLLATION_NAME, ID FROM information_schema.COLLATIONS WHERE ID<256 ORDER BY ID
1718
//
1819
// Handshake packet have only 1 byte for collation_id. So we can't use collations with ID > 255.
1920
//

‎conncheck.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
77
// You can obtain one at http://mozilla.org/MPL/2.0/.
88

9+
//go:build linux || darwin || dragonfly || freebsd || netbsd || openbsd || solaris || illumos
910
// +build linux darwin dragonfly freebsd netbsd openbsd solaris illumos
1011

1112
package mysql

‎conncheck_dummy.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
77
// You can obtain one at http://mozilla.org/MPL/2.0/.
88

9+
//go:build !linux && !darwin && !dragonfly && !freebsd && !netbsd && !openbsd && !solaris && !illumos
910
// +build !linux,!darwin,!dragonfly,!freebsd,!netbsd,!openbsd,!solaris,!illumos
1011

1112
package mysql

‎conncheck_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
77
// You can obtain one at http://mozilla.org/MPL/2.0/.
88

9+
//go:build linux || darwin || dragonfly || freebsd || netbsd || openbsd || solaris || illumos
910
// +build linux darwin dragonfly freebsd netbsd openbsd solaris illumos
1011

1112
package mysql

‎connection.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func (mc *mysqlConn) Begin() (driver.Tx, error) {
104104
}
105105

106106
func (mc *mysqlConn) begin(readOnly bool) (driver.Tx, error) {
107-
if mc.closed.IsSet() {
107+
if mc.closed.Load() {
108108
errLog.Print(ErrInvalidConn)
109109
return nil, driver.ErrBadConn
110110
}
@@ -123,7 +123,7 @@ func (mc *mysqlConn) begin(readOnly bool) (driver.Tx, error) {
123123

124124
func (mc *mysqlConn) Close() (err error) {
125125
// Makes Close idempotent
126-
if !mc.closed.IsSet() {
126+
if !mc.closed.Load() {
127127
err = mc.writeCommandPacket(comQuit)
128128
}
129129

@@ -137,7 +137,7 @@ func (mc *mysqlConn) Close() (err error) {
137137
// is called before auth or on auth failure because MySQL will have already
138138
// closed the network connection.
139139
func (mc *mysqlConn) cleanup() {
140-
if !mc.closed.TrySet(true) {
140+
if mc.closed.Swap(true) {
141141
return
142142
}
143143

@@ -152,7 +152,7 @@ func (mc *mysqlConn) cleanup() {
152152
}
153153

154154
func (mc *mysqlConn) error() error {
155-
if mc.closed.IsSet() {
155+
if mc.closed.Load() {
156156
if err := mc.canceled.Value(); err != nil {
157157
return err
158158
}
@@ -162,7 +162,7 @@ func (mc *mysqlConn) error() error {
162162
}
163163

164164
func (mc *mysqlConn) Prepare(query string) (driver.Stmt, error) {
165-
if mc.closed.IsSet() {
165+
if mc.closed.Load() {
166166
errLog.Print(ErrInvalidConn)
167167
return nil, driver.ErrBadConn
168168
}
@@ -295,7 +295,7 @@ func (mc *mysqlConn) interpolateParams(query string, args []driver.Value) (strin
295295
}
296296

297297
func (mc *mysqlConn) Exec(query string, args []driver.Value) (driver.Result, error) {
298-
if mc.closed.IsSet() {
298+
if mc.closed.Load() {
299299
errLog.Print(ErrInvalidConn)
300300
return nil, driver.ErrBadConn
301301
}
@@ -356,7 +356,7 @@ func (mc *mysqlConn) Query(query string, args []driver.Value) (driver.Rows, erro
356356
}
357357

358358
func (mc *mysqlConn) query(query string, args []driver.Value) (*textRows, error) {
359-
if mc.closed.IsSet() {
359+
if mc.closed.Load() {
360360
errLog.Print(ErrInvalidConn)
361361
return nil, driver.ErrBadConn
362362
}
@@ -450,7 +450,7 @@ func (mc *mysqlConn) finish() {
450450

451451
// Ping implements driver.Pinger interface
452452
func (mc *mysqlConn) Ping(ctx context.Context) (err error) {
453-
if mc.closed.IsSet() {
453+
if mc.closed.Load() {
454454
errLog.Print(ErrInvalidConn)
455455
return driver.ErrBadConn
456456
}
@@ -469,7 +469,7 @@ func (mc *mysqlConn) Ping(ctx context.Context) (err error) {
469469

470470
// BeginTx implements driver.ConnBeginTx interface
471471
func (mc *mysqlConn) BeginTx(ctx context.Context, opts driver.TxOptions) (driver.Tx, error) {
472-
if mc.closed.IsSet() {
472+
if mc.closed.Load() {
473473
return nil, driver.ErrBadConn
474474
}
475475

@@ -636,7 +636,7 @@ func (mc *mysqlConn) CheckNamedValue(nv *driver.NamedValue) (err error) {
636636
// ResetSession implements driver.SessionResetter.
637637
// (From Go 1.10)
638638
func (mc *mysqlConn) ResetSession(ctx context.Context) error {
639-
if mc.closed.IsSet() {
639+
if mc.closed.Load() {
640640
return driver.ErrBadConn
641641
}
642642
mc.reset = true
@@ -646,5 +646,5 @@ func (mc *mysqlConn) ResetSession(ctx context.Context) error {
646646
// IsValid implements driver.Validator interface
647647
// (From Go 1.15)
648648
func (mc *mysqlConn) IsValid() bool {
649-
return !mc.closed.IsSet()
649+
return !mc.closed.Load()
650650
}

‎connection_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ func TestCleanCancel(t *testing.T) {
147147
t.Errorf("expected context.Canceled, got %#v", err)
148148
}
149149

150-
if mc.closed.IsSet() {
150+
if mc.closed.Load() {
151151
t.Error("expected mc is not closed, closed actually")
152152
}
153153

‎driver.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
//
99
// The driver should be used via the database/sql package:
1010
//
11-
// import "database/sql"
12-
// import _ "github.com/go-sql-driver/mysql"
11+
// import "database/sql"
12+
// import _ "github.com/go-sql-driver/mysql"
1313
//
14-
// db, err := sql.Open("mysql", "user:password@/dbname")
14+
// db, err := sql.Open("mysql", "user:password@/dbname")
1515
//
1616
// See https://github.com/go-sql-driver/mysql#usage for details
1717
package mysql

‎fuzz.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
77
// You can obtain one at http://mozilla.org/MPL/2.0/.
88

9+
//go:build gofuzz
910
// +build gofuzz
1011

1112
package mysql

‎infile.go

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,11 @@ var (
2828
// Alternatively you can allow the use of all local files with
2929
// the DSN parameter 'allowAllFiles=true'
3030
//
31-
// filePath := "/home/gopher/data.csv"
32-
// mysql.RegisterLocalFile(filePath)
33-
// err := db.Exec("LOAD DATA LOCAL INFILE '" + filePath + "' INTO TABLE foo")
34-
// if err != nil {
35-
// ...
36-
//
31+
// filePath := "/home/gopher/data.csv"
32+
// mysql.RegisterLocalFile(filePath)
33+
// err := db.Exec("LOAD DATA LOCAL INFILE '" + filePath + "' INTO TABLE foo")
34+
// if err != nil {
35+
// ...
3736
func RegisterLocalFile(filePath string) {
3837
fileRegisterLock.Lock()
3938
// lazy map init
@@ -58,15 +57,14 @@ func DeregisterLocalFile(filePath string) {
5857
// If the handler returns a io.ReadCloser Close() is called when the
5958
// request is finished.
6059
//
61-
// mysql.RegisterReaderHandler("data", func() io.Reader {
62-
// var csvReader io.Reader // Some Reader that returns CSV data
63-
// ... // Open Reader here
64-
// return csvReader
65-
// })
66-
// err := db.Exec("LOAD DATA LOCAL INFILE 'Reader::data' INTO TABLE foo")
67-
// if err != nil {
68-
// ...
69-
//
60+
// mysql.RegisterReaderHandler("data", func() io.Reader {
61+
// var csvReader io.Reader // Some Reader that returns CSV data
62+
// ... // Open Reader here
63+
// return csvReader
64+
// })
65+
// err := db.Exec("LOAD DATA LOCAL INFILE 'Reader::data' INTO TABLE foo")
66+
// if err != nil {
67+
// ...
7068
func RegisterReaderHandler(name string, handler func() io.Reader) {
7169
readerRegisterLock.Lock()
7270
// lazy map init

‎nulltime.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@ import (
1919
// NullTime implements the Scanner interface so
2020
// it can be used as a scan destination:
2121
//
22-
// var nt NullTime
23-
// err := db.QueryRow("SELECT time FROM foo WHERE id=?", id).Scan(&nt)
24-
// ...
25-
// if nt.Valid {
26-
// // use nt.Time
27-
// } else {
28-
// // NULL value
29-
// }
22+
// var nt NullTime
23+
// err := db.QueryRow("SELECT time FROM foo WHERE id=?", id).Scan(&nt)
24+
// ...
25+
// if nt.Valid {
26+
// // use nt.Time
27+
// } else {
28+
// // NULL value
29+
// }
3030
//
31-
// This NullTime implementation is not driver-specific
31+
// # This NullTime implementation is not driver-specific
3232
//
3333
// Deprecated: NullTime doesn't honor the loc DSN parameter.
3434
// NullTime.Scan interprets a time as UTC, not the loc DSN parameter.

‎statement.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ type mysqlStmt struct {
2323
}
2424

2525
func (stmt *mysqlStmt) Close() error {
26-
if stmt.mc == nil || stmt.mc.closed.IsSet() {
26+
if stmt.mc == nil || stmt.mc.closed.Load() {
2727
// driver.Stmt.Close can be called more than once, thus this function
2828
// has to be idempotent.
2929
// See also Issue #450 and golang/go#16019.
@@ -50,7 +50,7 @@ func (stmt *mysqlStmt) CheckNamedValue(nv *driver.NamedValue) (err error) {
5050
}
5151

5252
func (stmt *mysqlStmt) Exec(args []driver.Value) (driver.Result, error) {
53-
if stmt.mc.closed.IsSet() {
53+
if stmt.mc.closed.Load() {
5454
errLog.Print(ErrInvalidConn)
5555
return nil, driver.ErrBadConn
5656
}
@@ -98,7 +98,7 @@ func (stmt *mysqlStmt) Query(args []driver.Value) (driver.Rows, error) {
9898
}
9999

100100
func (stmt *mysqlStmt) query(args []driver.Value) (*binaryRows, error) {
101-
if stmt.mc.closed.IsSet() {
101+
if stmt.mc.closed.Load() {
102102
errLog.Print(ErrInvalidConn)
103103
return nil, driver.ErrBadConn
104104
}
@@ -157,7 +157,7 @@ func (c converter) ConvertValue(v interface{}) (driver.Value, error) {
157157
if driver.IsValue(sv) {
158158
return sv, nil
159159
}
160-
// A value returend from the Valuer interface can be "a type handled by
160+
// A value returned from the Valuer interface can be "a type handled by
161161
// a database driver's NamedValueChecker interface" so we should accept
162162
// uint64 here as well.
163163
if u, ok := sv.(uint64); ok {

‎transaction.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ type mysqlTx struct {
1313
}
1414

1515
func (tx *mysqlTx) Commit() (err error) {
16-
if tx.mc == nil || tx.mc.closed.IsSet() {
16+
if tx.mc == nil || tx.mc.closed.Load() {
1717
return ErrInvalidConn
1818
}
1919
err = tx.mc.exec("COMMIT")
@@ -22,7 +22,7 @@ func (tx *mysqlTx) Commit() (err error) {
2222
}
2323

2424
func (tx *mysqlTx) Rollback() (err error) {
25-
if tx.mc == nil || tx.mc.closed.IsSet() {
25+
if tx.mc == nil || tx.mc.closed.Load() {
2626
return ErrInvalidConn
2727
}
2828
err = tx.mc.exec("ROLLBACK")

‎utils.go

Lines changed: 21 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -35,26 +35,25 @@ var (
3535
// Note: The provided tls.Config is exclusively owned by the driver after
3636
// registering it.
3737
//
38-
// rootCertPool := x509.NewCertPool()
39-
// pem, err := ioutil.ReadFile("/path/ca-cert.pem")
40-
// if err != nil {
41-
// log.Fatal(err)
42-
// }
43-
// if ok := rootCertPool.AppendCertsFromPEM(pem); !ok {
44-
// log.Fatal("Failed to append PEM.")
45-
// }
46-
// clientCert := make([]tls.Certificate, 0, 1)
47-
// certs, err := tls.LoadX509KeyPair("/path/client-cert.pem", "/path/client-key.pem")
48-
// if err != nil {
49-
// log.Fatal(err)
50-
// }
51-
// clientCert = append(clientCert, certs)
52-
// mysql.RegisterTLSConfig("custom", &tls.Config{
53-
// RootCAs: rootCertPool,
54-
// Certificates: clientCert,
55-
// })
56-
// db, err := sql.Open("mysql", "user@tcp(localhost:3306)/test?tls=custom")
57-
//
38+
// rootCertPool := x509.NewCertPool()
39+
// pem, err := ioutil.ReadFile("/path/ca-cert.pem")
40+
// if err != nil {
41+
// log.Fatal(err)
42+
// }
43+
// if ok := rootCertPool.AppendCertsFromPEM(pem); !ok {
44+
// log.Fatal("Failed to append PEM.")
45+
// }
46+
// clientCert := make([]tls.Certificate, 0, 1)
47+
// certs, err := tls.LoadX509KeyPair("/path/client-cert.pem", "/path/client-key.pem")
48+
// if err != nil {
49+
// log.Fatal(err)
50+
// }
51+
// clientCert = append(clientCert, certs)
52+
// mysql.RegisterTLSConfig("custom", &tls.Config{
53+
// RootCAs: rootCertPool,
54+
// Certificates: clientCert,
55+
// })
56+
// db, err := sql.Open("mysql", "user@tcp(localhost:3306)/test?tls=custom")
5857
func RegisterTLSConfig(key string, config *tls.Config) error {
5958
if _, isBool := readBool(key); isBool || strings.ToLower(key) == "skip-verify" || strings.ToLower(key) == "preferred" {
6059
return fmt.Errorf("key '%s' is reserved", key)
@@ -796,39 +795,10 @@ func (*noCopy) Lock() {}
796795
// https://github.com/golang/go/issues/26165
797796
func (*noCopy) Unlock() {}
798797

799-
// atomicBool is a wrapper around uint32 for usage as a boolean value with
800-
// atomic access.
801-
type atomicBool struct {
802-
_noCopy noCopy
803-
value uint32
804-
}
805-
806-
// IsSet returns whether the current boolean value is true
807-
func (ab *atomicBool) IsSet() bool {
808-
return atomic.LoadUint32(&ab.value) > 0
809-
}
810-
811-
// Set sets the value of the bool regardless of the previous value
812-
func (ab *atomicBool) Set(value bool) {
813-
if value {
814-
atomic.StoreUint32(&ab.value, 1)
815-
} else {
816-
atomic.StoreUint32(&ab.value, 0)
817-
}
818-
}
819-
820-
// TrySet sets the value of the bool and returns whether the value changed
821-
func (ab *atomicBool) TrySet(value bool) bool {
822-
if value {
823-
return atomic.SwapUint32(&ab.value, 1) == 0
824-
}
825-
return atomic.SwapUint32(&ab.value, 0) > 0
826-
}
827-
828798
// atomicError is a wrapper for atomically accessed error values
829799
type atomicError struct {
830-
_noCopy noCopy
831-
value atomic.Value
800+
_ noCopy
801+
value atomic.Value
832802
}
833803

834804
// Set sets the error value regardless of the previous value.

‎utils_test.go

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -173,66 +173,6 @@ func TestEscapeQuotes(t *testing.T) {
173173
expect("foo\"bar", "foo\"bar") // not affected
174174
}
175175

176-
func TestAtomicBool(t *testing.T) {
177-
var ab atomicBool
178-
if ab.IsSet() {
179-
t.Fatal("Expected value to be false")
180-
}
181-
182-
ab.Set(true)
183-
if ab.value != 1 {
184-
t.Fatal("Set(true) did not set value to 1")
185-
}
186-
if !ab.IsSet() {
187-
t.Fatal("Expected value to be true")
188-
}
189-
190-
ab.Set(true)
191-
if !ab.IsSet() {
192-
t.Fatal("Expected value to be true")
193-
}
194-
195-
ab.Set(false)
196-
if ab.value != 0 {
197-
t.Fatal("Set(false) did not set value to 0")
198-
}
199-
if ab.IsSet() {
200-
t.Fatal("Expected value to be false")
201-
}
202-
203-
ab.Set(false)
204-
if ab.IsSet() {
205-
t.Fatal("Expected value to be false")
206-
}
207-
if ab.TrySet(false) {
208-
t.Fatal("Expected TrySet(false) to fail")
209-
}
210-
if !ab.TrySet(true) {
211-
t.Fatal("Expected TrySet(true) to succeed")
212-
}
213-
if !ab.IsSet() {
214-
t.Fatal("Expected value to be true")
215-
}
216-
217-
ab.Set(true)
218-
if !ab.IsSet() {
219-
t.Fatal("Expected value to be true")
220-
}
221-
if ab.TrySet(true) {
222-
t.Fatal("Expected TrySet(true) to fail")
223-
}
224-
if !ab.TrySet(false) {
225-
t.Fatal("Expected TrySet(false) to succeed")
226-
}
227-
if ab.IsSet() {
228-
t.Fatal("Expected value to be false")
229-
}
230-
231-
// we've "tested" them ¯\_(ツ)_/¯
232-
ab._noCopy.Lock()
233-
defer ab._noCopy.Unlock()
234-
}
235-
236176
func TestAtomicError(t *testing.T) {
237177
var ae atomicError
238178
if ae.Value() != nil {

0 commit comments

Comments
 (0)
Please sign in to comment.