github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/dm/chaos/cases/result.go (about)

     1  // Copyright 2020 PingCAP, Inc.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // See the License for the specific language governing permissions and
    12  // limitations under the License.
    13  
    14  package main
    15  
    16  import "encoding/json"
    17  
    18  // singleResult holds the result of a single source.
    19  type singleResult struct {
    20  	Insert int `json:"insert"`
    21  	Update int `json:"update"`
    22  	Delete int `json:"delete"`
    23  	DDL    int `json:"ddl"`
    24  }
    25  
    26  func (sr singleResult) String() string {
    27  	data, err := json.Marshal(sr)
    28  	if err != nil {
    29  		return err.Error()
    30  	}
    31  	return string(data)
    32  }
    33  
    34  // results holds the results of single or multiple sources task case.
    35  type results []singleResult
    36  
    37  func (r results) String() string {
    38  	data, err := json.Marshal(r)
    39  	if err != nil {
    40  		return err.Error()
    41  	}
    42  	return string(data)
    43  }