package launch import ( "errors" "fmt" "testing" ) type lostWrite struct{} func (lostWrite) Error() string { return "issues.numbers.issue: the key was written by another writer first" } func (lostWrite) ErrorCode() int { return CodeChanged } // A lost compare-and-set is answered to a bundle with its own code, wrapped or not, and the SDK tells it by // that code alone (mesh-sdk's stdio.CodeChanged); every other refusal is the general code, never that one. func TestALostWriteIsAnsweredWithItsOwnCodeAndNothingElseIs(t *testing.T) { if CodeChanged != -32010 { t.Fatalf("the lost-write code is %d; mesh-sdk tells it by -32010", CodeChanged) } for _, err := range []error{lostWrite{}, fmt.Errorf("asked by issues: %w", lostWrite{})} { if got := errorCode(err); got != CodeChanged { t.Errorf("%v is answered %d", err, got) } } if got := errorCode(errors.New("issues keeps no state numbers")); got == CodeChanged || got != -32000 { t.Errorf("a plain refusal is answered %d", got) } }