Skip to content

Commit

Permalink
Merge pull request #4 from homenoc/develop
Browse files Browse the repository at this point in the history
Fix
  • Loading branch information
yoneyan authored Aug 26, 2021
2 parents 6a85de9 + fc753de commit 7f9d470
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 95 deletions.
1 change: 0 additions & 1 deletion jpnic.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ func (c *Config) Send(input WebTransaction) Result {
if strings.Contains(scanner.Text(), "TECH2_JPNIC_HDL=") {
result.Tech2JPNICHdl = scanner.Text()[16:]
}
fmt.Println(scanner.Text())

}

Expand Down
185 changes: 91 additions & 94 deletions jpnic_test.go
Original file line number Diff line number Diff line change
@@ -1,105 +1,102 @@
package jpnic

import (
"bufio"
"strconv"
"strings"
"testing"
)

func TestResultProcess(t *testing.T) {
var result Result

str := "<html>\n<body>\nRET=00\nRET_CODE=00000000\nRECEP_NO=001\nRECEP_HSNO=0\nADM_JPNIC_HDL=JP00\nADM_GNAME_JP=Y-Net\nTECH1_JPNIC_HDL=JP00\nTECH1_GNAME_JP=Y-Net\nTECH2_JPNIC_HDL=\nTECH2_GNAME_JP=\nCOUNT=0\n</body>\n</html>"
reader := strings.NewReader(str)
scanner := bufio.NewScanner(reader)

success := false
var retCode []string
ret := "00"

for scanner.Scan() {
// RET
if strings.Contains(scanner.Text(), "RET=") {
t.Logf("Error: %s", scanner.Text()[4:])
ret = scanner.Text()[4:]
if scanner.Text()[4:] == "00" {
success = true
}
ret = scanner.Text()[4:]
}

// RET_CODE
if strings.Contains(scanner.Text(), "RET_CODE=") {
t.Logf("RET_CODE Error: %s", scanner.Text()[9:])
retCode = append(retCode, scanner.Text()[9:])
}

// RECEP_NO
if strings.Contains(scanner.Text(), "RECEP_NO=") {
t.Logf("RECEP_NO=%s", scanner.Text()[9:])
result.RecepNo = scanner.Text()[9:]
}

// Admin
if strings.Contains(scanner.Text(), "ADM_JPNIC_HDL=") {
t.Logf("ADM_JPNIC_HDL=%s", scanner.Text()[14:])
result.AdmJPNICHdl = scanner.Text()[14:]
}

// Tech1
if strings.Contains(scanner.Text(), "TECH1_JPNIC_HDL=") {
t.Logf("TECH1_JPNIC_HDL=%s", scanner.Text()[16:])
result.Tech1JPNICHdl = scanner.Text()[16:]
}

// Tech2
if strings.Contains(scanner.Text(), "TECH2_JPNIC_HDL=") {
t.Logf("TECH2_JPNIC_HDL=%s", scanner.Text()[16:])
result.Tech2JPNICHdl = scanner.Text()[16:]
}

t.Log(scanner.Text())
}
//func TestResultProcess(t *testing.T) {
// var result Result
//
// str := "<html>\n<body>\nRET=00\nRET_CODE=00000000\nRECEP_NO=001\nRECEP_HSNO=0\nADM_JPNIC_HDL=JP00\nADM_GNAME_JP=Y-Net\nTECH1_JPNIC_HDL=JP00\nTECH1_GNAME_JP=Y-Net\nTECH2_JPNIC_HDL=\nTECH2_GNAME_JP=\nCOUNT=0\n</body>\n</html>"
// reader := strings.NewReader(str)
// scanner := bufio.NewScanner(reader)
//
// success := false
// var retCode []string
// ret := "00"
//
// for scanner.Scan() {
// // RET
// if strings.Contains(scanner.Text(), "RET=") {
// t.Logf("Error: %s", scanner.Text()[4:])
// ret = scanner.Text()[4:]
// if scanner.Text()[4:] == "00" {
// success = true
// }
// ret = scanner.Text()[4:]
// }
//
// // RET_CODE
// if strings.Contains(scanner.Text(), "RET_CODE=") {
// t.Logf("RET_CODE Error: %s", scanner.Text()[9:])
// retCode = append(retCode, scanner.Text()[9:])
// }
//
// // RECEP_NO
// if strings.Contains(scanner.Text(), "RECEP_NO=") {
// t.Logf("RECEP_NO=%s", scanner.Text()[9:])
// result.RecepNo = scanner.Text()[9:]
// }
//
// // Admin
// if strings.Contains(scanner.Text(), "ADM_JPNIC_HDL=") {
// t.Logf("ADM_JPNIC_HDL=%s", scanner.Text()[14:])
// result.AdmJPNICHdl = scanner.Text()[14:]
// }
//
// // Tech1
// if strings.Contains(scanner.Text(), "TECH1_JPNIC_HDL=") {
// t.Logf("TECH1_JPNIC_HDL=%s", scanner.Text()[16:])
// result.Tech1JPNICHdl = scanner.Text()[16:]
// }
//
// // Tech2
// if strings.Contains(scanner.Text(), "TECH2_JPNIC_HDL=") {
// t.Logf("TECH2_JPNIC_HDL=%s", scanner.Text()[16:])
// result.Tech2JPNICHdl = scanner.Text()[16:]
// }
//
// t.Log(scanner.Text())
// }
//
// // RET
// if ret != "00" {
// code, _ := strconv.Atoi(ret)
// ErrorStatusText(code)
// }
//
// // RET_CODE
// for _, code := range retCode {
// var errStr string
// t.Logf("%s", code[4:7])
//
// // interface
// if code[4:7] == "000" {
// code, _ := strconv.Atoi(code[4:7])
// errStr += ErrorStatusText(code)
//
// }
//
// // error genre
// if code[7:] != "0" {
// code, _ := strconv.Atoi(code[7:])
// errStr += "_" + ErrorStatusText(code)
// }
// }
// t.Log(success)
//}

// RET
if ret != "00" {
code, _ := strconv.Atoi(ret)
ErrorStatusText(code)
func TestSend(t *testing.T) {
con := Config{
URL: "",
CertFilePath: "/home/yonedayuto/Documents/HomeNOC/cert/v4-cert.pem",
KeyFilePath: "/home/yonedayuto/Documents/HomeNOC/cert/v4-prvkey.pem",
CAFilePath: "/home/yonedayuto/Documents/HomeNOC/cert/rootcacert_r3.cer",
}
input := WebTransaction{}

// RET_CODE
for _, code := range retCode {
var errStr string
t.Logf("%s", code[4:7])

// interface
if code[4:7] == "000" {
code, _ := strconv.Atoi(code[4:7])
errStr += ErrorStatusText(code)

}

// error genre
if code[7:] != "0" {
code, _ := strconv.Atoi(code[7:])
errStr += "_" + ErrorStatusText(code)
}
err := con.Send(input)
if err.Err != nil {
t.Log(err)
}
t.Log(success)
}

//func SendTest(t *testing.T) {
// con := Config{
// URL: "",
// CertFilePath: "",
// KeyFilePath: "",
// CAFilePath: "",
// }
// input := WebTransaction{}
//
// err := con.Send(input)
// if err != nil {
// log.Println(err)
// }
//}

0 comments on commit 7f9d470

Please sign in to comment.