Skip to content
Snippets Groups Projects
helper_test.go 575 B
Newer Older
  • Learn to ignore specific revisions
  • package net
    
    import (
    	"testing"
    
    
    	"github.com/stretchr/testify/assert"
    )
    
    
    Oliver Herms's avatar
    Oliver Herms committed
    func TestIPv4ToUint32(t *testing.T) {
    
    	tests := []struct {
    		input    []byte
    		expected uint32
    	}{
    		{
    			input:    []byte{192, 168, 1, 5},
    			expected: 3232235781,
    		},
    		{
    			input:    []byte{10, 0, 0, 0},
    			expected: 167772160,
    		},
    		{
    			input:    []byte{172, 24, 5, 1},
    			expected: 2887255297,
    		},
    
    		{
    			input:    net.ParseIP("172.24.5.1"),
    			expected: 2887255297,
    		},
    
    	}
    
    	for _, test := range tests {
    		res := IPv4ToUint32(test.input)
    		assert.Equal(t, test.expected, res)
    	}
    }